﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace NeuralNetworkPCL
{
    internal class DataCollection
    {
        DataPoint[] trainingPoints;
        DataPoint[] generalisationPoints;

        internal DataCollection(String [] _content, int _outputNb, double _trainingRatio)
        {
            // Read points
            int nbLines = _content.Length;
            List<DataPoint> points = new List<DataPoint>();
            for (int i = 0; i < nbLines; i++)
            {
                points.Add(new DataPoint(_content[i], _outputNb));
            }

            // Training set
            int nbTrainingPoints = (int) (_trainingRatio * nbLines);
            trainingPoints = new DataPoint[nbTrainingPoints];
            Random rand = new Random();
            for (int i = 0; i < nbTrainingPoints; i++)
            {
                int index = rand.Next (points.Count);
                trainingPoints[i] = points.ElementAt(index);
                points.RemoveAt(index);
            }

            // Generalisation set
            generalisationPoints = points.ToArray();
        }

        internal DataPoint[] Points()
        {
            return trainingPoints;
        }

        internal DataPoint[] GeneralisationPoints()
        {
            return generalisationPoints;
        }
    }
}
